package id.co.shuba.spamobile.widget;

import java.util.List;

import id.co.shuba.spamobile.R;
import id.co.shuba.spamobile.model.StandardInfo;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class StandardAdapter extends BaseAdapter {
	private final Activity context;
	private final List<StandardInfo> list;
	

	public StandardAdapter(Activity context, List<StandardInfo> list) {		
		this.context = context;
		this.list = list;
	}	
	
	public View getView(int position, View convertView, ViewGroup parent) {
		View rowView = convertView;
		if (rowView == null) {
			LayoutInflater inflater = context.getLayoutInflater();
			rowView = inflater.inflate(R.layout.simple_item, null);			
			TextView text = (TextView) rowView.findViewById(R.id.txtName);								
			rowView.setTag(text);
		}

		TextView txt = (TextView) rowView.getTag();
		StandardInfo info = list.get(position);
		txt.setText(info.getText());		

		return rowView;
	}

	public int getCount() {
		return list.size();
	}

	public Object getItem(int arg0) {
		return list.get(arg0);
	}	

	public long getItemId(int arg0) {		
		return 0;
	}
	
	public int getPosition(String value) {
		int i = 0;
		for (StandardInfo info : list) {
			if (info.getValue().equals(value))
				return i;
			i++;
		}
		return -1;
	}
}
